/*
 * PanoramaBuffer.cpp
 *
 *  Created on: 12 Apr 2011
 *      Author: s88900
 */

#include "PanoramaBuffer.h"

PanoramaBuffer::PanoramaBuffer() {
	for (int i = 0; i < 10; i++) {
		buffer[i] = new Picture();
	}
	_in = 0;
	_out = 0;
}

void PanoramaBuffer::in(string s) {
	//cout << "buffer[" << _in << "] changed to \"" << s << "\"" << endl;
	//cout << "in: " << _in << endl;
	buffer[_in]->write(s);
	_in = cycle(_in);
}

string PanoramaBuffer::out() {
	_out = cycle(_out);
	//cout << "out: " << _out << endl;
	return buffer[_out]->read();
}

int PanoramaBuffer::cycle(int i) {
	if (i == 9) {
		return 0;
	}
	return i + 1;
}

PanoramaBuffer::~PanoramaBuffer() {
	for (int i = 0; i < 10; i++) {
		delete buffer[i];
	}
	delete buffer;
	_in = 0;
	_out = 0;
}
